﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace ELab.Core
{
    public class SystemConfiguration
    {
        public static string TransferFolder
        {
            get
            {
                var myConfig = ConfigurationManager.AppSettings["TransferFolder"];
                if (string.IsNullOrWhiteSpace(myConfig)) return "TransferFolder";
                return myConfig;
            }
        }

        private static string assemblyDirectory = null;
        public static string CurrentPath
        {
            get
            {
                if (!string.IsNullOrWhiteSpace(assemblyDirectory)) return assemblyDirectory;
                string codeBase = Assembly.GetExecutingAssembly().CodeBase;
                UriBuilder uri = new UriBuilder(codeBase);
                string path = Uri.UnescapeDataString(uri.Path);
                assemblyDirectory = Path.GetDirectoryName(path);
                return assemblyDirectory;
            }
        }

        private static int? connectTimeOut = null;
        public static int ConnectTimeOut
        {
            get
            {
                if (connectTimeOut.HasValue) return connectTimeOut.Value;
                string configTimeOut = ConfigurationManager.AppSettings["ConnectTimeOut"];
                int temp = 10;
                int.TryParse(configTimeOut, out temp);
                connectTimeOut = temp;
                return connectTimeOut.Value;
            }
        }

        private static int? reconnectTimes = null;
        public static int ReconnectTimes
        {
            get
            {
                if (reconnectTimes.HasValue) return reconnectTimes.Value;
                string reconnectTimeSetting = ConfigurationManager.AppSettings["ReconnectTimes"];
                int temp;
                if (int.TryParse(reconnectTimeSetting, out temp)) reconnectTimes = temp;
                return reconnectTimes ?? 5;
            }
        }
    }
}
